﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

public partial class Example3 : System.Web.UI.Page
{
    private void Page_Load(object sender, EventArgs e)
    {
        string xmlPath = Server.MapPath("Books.xml");
        XmlDocument doc = new XmlDocument();
        doc.Load(xmlPath);
        XmlNode rootNode = doc.DocumentElement;
        DisplayNodes(rootNode);
    }

    private void DisplayNodes(XmlNode node)
    {
        //Print the node type, node name and node value of the node
        if (node.NodeType == XmlNodeType.Text)
        {
            Response.Write("Type= [" + node.NodeType + "] Value=" + node.Value + "<br>");
        }
        else
        {
            Response.Write("Type= [" + node.NodeType + "] Name=" + node.Name + "<br>");
        }
        //Print attributes of the node


        if (node.Attributes != null)
        {
            XmlAttributeCollection attrs = node.Attributes;
            foreach (XmlAttribute attr in attrs)
            {
                Response.Write("Attribute Name =" + attr.Name + "Attribute Value =" + attr.Value);
            }
        }
        //Print individual children of the node
        XmlNodeList children = node.ChildNodes;
        foreach (XmlNode child in children)
        {
            DisplayNodes(child);
        }
    }
}